package com.aaa.order.controller;

import com.aaa.entity.Order;
import com.aaa.entity.Product;
import com.aaa.order.feign.ProductFeign;
import com.aaa.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author ：Username 刘亦辰（59372312@qq.com）
 * @date ：Created in 2022/11/18 1:04
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/order")
public class OrderController01 {
    @Autowired
    ProductFeign productFeign;
    @Autowired
    OrderService orderService;
    @Autowired
    DiscoveryClient discoveryClient;

    @RequestMapping("show")
    public String show(){
        return "ok";
    }


    @GetMapping("/saveOrder")
    public String saveOrder(Long pid,Integer num) {

        Order order = new Order();
        //用户得信息可以从登录后获取--Session  redis  jwt
        order.setUid(1);
        order.setUsername("刘亦辰");
        //为订单对象设置商品得信息
        order.setPid(pid);
        //使用远程调用组件远程调用商品微服务提供得接口---后面
        //使用组件调用其他服务的方法 就如同调用自身方法一样
        Product product = productFeign.getById(pid);
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());
        order.setNumber(num);
        orderService.save(order);
        return  "下单成功！";

    }
}

